#ifndef __IPC_LOG_H__
#define __IPC_LOG_H__

#include <syslog.h>
#include <stdio.h>
#include <stdarg.h>
#include "ipc_typedef.h"

#define MAX_LOG_LINE_LEN (BUF_LEN_1024)
#define IPC_LOG_FILE_NAME ("/tmp/ipcLog.log")

//better same as syslog define
typedef enum
{
	IPC_LOG_EMERG = 0,
	IPC_LOG_ALERT = 1,
	IPC_LOG_CRIT = 2,
	IPC_LOG_ERR = 3,
	IPC_LOG_WARNING = 4,
	IPC_LOG_NOTICE = 5,
	IPC_LOG_INFO = 6,
	IPC_LOG_DEBUG = 7,
}ipcLogLevel_e;

typedef enum
{
	IPC_LOG_2_SYSLOG = 0,
	IPC_LOG_2_STDERR = 1,
	IPC_LOG_2_FILE = 2,
}ipcLogDstination_e;

typedef struct{
	ipcLogLevel_e			log_level;
	ipcLogDstination_e		log_destination;
}ipcLog_s;

ipcRet_e ipcLogInit(ipcLog_s *pLog);
ipcRet_e ipcLogDeinit(void);
void ipcLogIt(ipcLogLevel_e level,const char *pFmt, ... );

#define		ipcLogError(msg...) 	ipcLogIt(IPC_LOG_ERR,msg)
#define		ipcLogDebug(msg...) 	ipcLogIt(IPC_LOG_DEBUG,msg)
#define		ipcLogEmerg(msg...) 	ipcLogIt(IPC_LOG_EMERG,msg)

#define		ipcLogDebugFL		ipcLogIt(IPC_LOG_DEBUG,"FILE %s,LINE %d\n",__FILE__,__LINE__)
#define		ipcLogCheckNullPointReturnValue(ptr,ret) do{if(NULL == ptr) {\
				ipcLogError("NULL ptr function %s,line %d\n",__FUNCTION__,__LINE__);return ret;}}while(0);


#define		ipcLogCheckNullPointReturn(ptr) do{if(NULL == ptr) {\
				ipcLogError("NULL ptr function %s,line %d\n",__FUNCTION__,__LINE__);return ;}}while(0);

#define		ipcLogCheckRetThenReturn(ret) do{if(ipcSuccess != ret) {\
				ipcLogError("function %s,line %d failed\n",__FUNCTION__,__LINE__);return ret;}}while(0);

#endif
